﻿using RantopadService.Conn;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace RantopadService.Business
{
    public class ErrBusiness
    {
        public static DataTable getAllErr()
        {
            string mysql = "SELECT * FROM rantopad.errinfo";
            var dt = MyMySqlHelper.Query(mysql).Tables[0];
            return dt;
        }
        public static DataTable getAllErr(string userid, DateTime st, DateTime et)
        {
            string mysql = "SELECT * FROM rantopad.errinfo  where tm>'{0}' and tm<='{1}' ";
            if (userid != "")
            {
                mysql = mysql + "and username='{2}'";
                mysql = string.Format(mysql, st.ToString(), et.ToString(), userid);
            }
            else
            {
                mysql = string.Format(mysql, st.ToString(), et.ToString());
            }


            var dt = MyMySqlHelper.Query(mysql).Tables[0];
            return dt;
        }
        public static int delErr(DataTable dt)
        {
            //string mysql = "delete * from rantopad.errinfo  ";
            //return MyMySqlHelper.ExecuteSql(mysql);
            return 0;
        }
        public static int delErr(string id)
        {
            string mysql = "delete  from rantopad.errinfo  where errid='{0}'";
            mysql = string.Format(mysql, id);

            return MyMySqlHelper.ExecuteSql(mysql);

        }
        public static int addErr(string username, DateTime tm, string errmsg)
        {

            string mysql = "insert into rantopad.errinfo (`username`, `tm`, `errmsg`) VALUES ('{0}', '{1}', '{2}') ";
            mysql = string.Format(mysql, username, tm, errmsg);
            return MyMySqlHelper.ExecuteSql(mysql);

        }

        internal static DataTable  getAllErr(string wherelike)
        {
            string mysql = "SELECT * FROM rantopad.errinfo where username like '%{0}%' or errmsg like '%{0}%' or tm like '%{0}%'";
            mysql = string.Format(mysql, wherelike);
            var dt = MyMySqlHelper.Query(mysql).Tables[0];
            return dt;
        }
    }
}